Skip to content

Conversation

nasmovk
Copy link
Contributor

@nasmovk nasmovk commented Sep 30, 2025

Rewrite of the print_table output method.

This is in response to the need for greater control over column widths and other formatting options such as borders, alignments, and row striping.

The method is rewritten to directly output an HTML table instead of the original markdown approach. It introduces more CSS options through classes. This in turn allows different formatting options to be specified for each table in the same output window (which was limited in the original).

The new functionality can be optionally called with new kwargs. If these are not specified, the original functionality of the old print_table is maintained.

It adds some data validation to check that arguments of type list are of the same length.

Another improvement: It allows several tables in one output to have their own formatting options.

Finally, this contribution should make it easier to later implement HTML colspan options to make more flexible tables/

Checklist OK

Related Issues

https://discourse.pyrevitlabs.io/t/pyrevit-output-table-formatting/1532/13

Additional Notes

I attach a button script that runs the new method to show it in action.

Nobody asked for contribution, but it is very useful to me already.
I am sure my python is amateurish, but I think it works well.

TABOUTPUTDEV_script.py

Rewrite of the print_table output method.

This is in response to the need for greater control over column widths and other formatting options.

The method is rewritten to directly output an HTML table instead of the original markdown approach. It introduces more CSS options through classes. This in turn allows different formatting options to be specified for each table in the same output window (which was limited in the original).

The new funcionality can be optionally called with new kwargs. If these are not specified, the original functionality of the old print_table is maintained. 

It adds some data validation to check that arguments of type list are of the same length.

Finally, this contribution should male it easier to later implement HTML colspan options to make more flexible tables.
Small optimisation removing superfluous else s in the table_check_input_lists method
Minor update, addin the border style to the header row.
Copy link
Contributor

devloai bot commented Sep 30, 2025

Unable to perform a code review. You have run out of credits 😔
Please upgrade your plan or buy additional credits from the subscription page.

@jmcouffin jmcouffin changed the title output __init__ rewrite of the print_table function Rewrite of the print_table function: module "output" __init__.py Sep 30, 2025

# Set a unique ID for each table
# This is used in HTML tags to define CSS classes for formatting per table
table_uid = random.randint(10000, 99999)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better use a counter, there is a small chance you hit a bug
set the variable somewhere higher:
self._table_counter = 0
then

self._table_counter += 1
table_uid = self._table_counter

@jmcouffin
Copy link
Contributor

Have you tested it on tools containing old table behaviour: preflight checks audit all, line counter for example

@jmcouffin
Copy link
Contributor

if it works well, this is a ool change that could require documentation on the notion docs.

@jmcouffin jmcouffin added Enhancement Enhancement request [class->Improved #{number}: {title}] Tools Issues related to pyRevit commands [subsystem] labels Sep 30, 2025
@nasmovk
Copy link
Contributor Author

nasmovk commented Oct 1, 2025

Hi Jean-Marc,
Thanks for the feedback.
I will make changes according to your comments.
Yes, I have tested it on all the existing pyRevit tool buttons that call the original print_table. I will recheck after making the next changes.

2025-10-01. Following JMC comments

31: Remove random import (from pyrevit.coreutils)

97: Add new __init__ to PyRevitOutputWindow class for a _table_counter

610: Correct logical error in kwarg validation

686: Implement _table_counter 

755: Replace verbose if with a compact one.
@nasmovk
Copy link
Contributor Author

nasmovk commented Oct 1, 2025

I have made a new Commit with the suggested changes.
I confirm I have tested on the existing tools that use print_table.
I agree that the Notion docs should be updated if my changes are accepted. I am happy to help with that.

- Added border_style parameter to table_html_header method for customizable table header styling.
- Updated docstrings for table_html_header and table_check_input_lists methods to include examples and clarify argument types.
- Improved input validation in table_check_input_lists to ensure consistent list lengths and provide detailed error messages.
@jmcouffin
Copy link
Contributor

I agree that the Notion docs should be updated if my changes are accepted. I am happy to help with that.

Can you take the content of the said page and make a new one on your own notion account, share me the link to update.
We don't have a pro account to share edit rights with Ehsan outside of the both of us. DM me ht elink in the forum

@jmcouffin jmcouffin merged commit 0fb8c5e into pyrevitlabs:develop Oct 7, 2025
Copy link
Contributor

github-actions bot commented Oct 7, 2025

📦 New work-in-progress (wip) builds are available for 5.2.0.25280+0218-wip

Copy link
Contributor

github-actions bot commented Oct 7, 2025

📦 New work-in-progress (wip) builds are available for 5.2.0.25280+1054-wip

Copy link
Contributor

github-actions bot commented Oct 7, 2025

📦 New work-in-progress (wip) builds are available for 5.2.0.25280+1057-wip

@nasmovk
Copy link
Contributor Author

nasmovk commented Oct 7, 2025

Hi. Yes, I'll get started on the Notion page.
Thanks.

@nasmovk nasmovk deleted the patch-2 branch October 8, 2025 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Enhancement request [class->Improved #{number}: {title}] Tools Issues related to pyRevit commands [subsystem]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants